package com.pig.goods.controller;
import com.pig.goods.service.CommentService;
import com.pig.pojo.commgoods.Comment;
import com.pig.pojo.commgoods.JsonResult;
import com.pig.pojo.commgoods.PageObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comm/")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 查询所有的商品信息
     * @param goodsId
     * @param pageCurrent
     * @return
     */
    @GetMapping("/doFindComment")
    public JsonResult doFindComment(Integer goodsId, Integer pageCurrent) {
        PageObject<Comment> poj = commentService.findCommentByGoodsId(goodsId, pageCurrent);
        return new JsonResult(poj);
    }

    /**
     * 添加评论方法
     * @param comment
     * @return
     */
    @RequestMapping("/doSaveComment")
    public JsonResult doSaveComment(Comment comment) {
        commentService.insertComment(comment);
        return new JsonResult("评论成功！");
    }
}
